<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	template="../templates/ui.xhtml">

    <ui:define name="head">
        <style type="text/css">
            
        </style>

        <script type="text/javascript">
            //<![CDATA[

            //]]>
        </script>
    </ui:define>

	<ui:define name="content">
	
		<h1 class="title ui-widget-header ui-corner-all">Client Side Validation - Bean Validation</h1>
		<div class="entry">
			<p>Client Side Validation Framework is integrated with Bean Validation Specification.</p>

			<h:form>
                <p:panel header="Validate">
                    <p:messages />
                    
                    <h:panelGrid columns="4" cellpadding="5">
                        <h:outputLabel for="name" value="Name: (@Size(min=2,max=5))" />
                        <p:inputText id="name" value="#{validationBean.name}" label="Name"/>
                        <p:message for="name" />
                        <h:outputText value="#{validationBean.name}" />
                        
                        <h:outputLabel for="age" value="Age: (@Min(10) @Max(20))" />
                        <p:inputText id="age" value="#{validationBean.age}" label="Age"/>
                        <p:message for="age" />
                        <h:outputText value="#{validationBean.age}" />
                        
                        <h:outputLabel for="amount" value="Amount: (@DecimalMax('99.9'))" />
                        <p:inputText id="amount" value="#{validationBean.amount}" label="Amount"/>
                        <p:message for="amount" />
                        <h:outputText value="#{validationBean.amount}" />
                        
                        <h:outputLabel for="amount2" value="Amount: (@Digits(integer=3,fraction=2))" />
                        <p:inputText id="amount2" value="#{validationBean.amount2}" label="Amount 2"/>
                        <p:message for="amount2" />
                        <h:outputText value="#{validationBean.amount2}" />
                        
                        <h:outputLabel for="pattern" value="Pattern: (@Pattern(regexp='^[-+]?\\d+$'))" />
                        <p:inputText id="pattern" value="#{validationBean.pattern}" label="pattern"/>
                        <p:message for="pattern" />
                        <h:outputText value="#{validationBean.pattern}" />
                        
                        <h:outputLabel for="checked" value="Assert: (@AssertTrue)" />
                        <p:selectBooleanCheckbox id="checked" value="#{validationBean.checked}" />
                        <p:message for="checked" />
                        <h:outputText/>
                                              
                        <h:outputLabel for="psstDate" value="Date (@Past)"/>                                
                        <p:inputText id="psstDate" value="#{validationBean.pastDate}">
                            <f:convertDateTime pattern="MM/dd/yyyy" />
                        </p:inputText> 
                        <p:message for="psstDate" />
                        <h:outputText/>
                        
                        <h:outputLabel for="futureDate" value="Date (@Future)"/>                                
                        <p:inputText id="futureDate" value="#{validationBean.futureDate}">
                            <f:convertDateTime pattern="MM/dd/yyyy" />
                        </p:inputText> 
                        <p:message for="futureDate" />
                        <h:outputText/>
                                                
                    </h:panelGrid>

                    <p:commandButton value="Save" ajax="false" icon="ui-icon-check" validateClient="true"/>
                </p:panel>
			</h:form>
			
			<h3>Source</h3>
			<p:tabView>
				<p:tab title="csvBean.xhtml">
                    <pre name="code" class="xml">
&lt;h:form&gt;
    &lt;p:panel header="Validate"&gt;
        &lt;p:messages /&gt;

        &lt;h:panelGrid columns="4" cellpadding="5"&gt;
            &lt;h:outputLabel for="name" value="Name: (@Size(min=2,max=5))" /&gt;
            &lt;p:inputText id="name" value="\#{validationBean.name}" label="Name"/&gt;
            &lt;p:message for="name" /&gt;
            &lt;h:outputText value="\#{validationBean.name}" /&gt;

            &lt;h:outputLabel for="age" value="Age: (@Min(10) @Max(20))" /&gt;
            &lt;p:inputText id="age" value="\#{validationBean.age}" label="Age"/&gt;
            &lt;p:message for="age" /&gt;
            &lt;h:outputText value="\#{validationBean.age}" /&gt;

            &lt;h:outputLabel for="amount" value="Amount: (@DecimalMax('99.9'))" /&gt;
            &lt;p:inputText id="amount" value="\#{validationBean.amount}" label="Amount"/&gt;
            &lt;p:message for="amount" /&gt;
            &lt;h:outputText value="\#{validationBean.amount}" /&gt;

            &lt;h:outputLabel for="amount2" value="Amount: (@Digits(integer=3,fraction=2))" /&gt;
            &lt;p:inputText id="amount2" value="\#{validationBean.amount2}" label="Amount 2"/&gt;
            &lt;p:message for="amount2" /&gt;
            &lt;h:outputText value="\#{validationBean.amount2}" /&gt;

            &lt;h:outputLabel for="pattern" value="Pattern: (@Pattern(regexp="^[-+]?\\d+$")))" /&gt;
            &lt;p:inputText id="pattern" value="\#{validationBean.pattern}" label="pattern"/&gt;
            &lt;p:message for="pattern" /&gt;
            &lt;h:outputText value="\#{validationBean.pattern}" /&gt;

            &lt;h:outputLabel for="checked" value="Assert: (@AssertTrue)" /&gt;
            &lt;p:selectBooleanCheckbox id="checked" value="\#{validationBean.checked}" /&gt;
            &lt;p:message for="checked" /&gt;
            &lt;h:outputText/&gt;

            &lt;h:outputLabel for="psstDate" value="Date (@Past)"/&gt;                                
            &lt;p:inputText id="psstDate" value="\#{validationBean.pastDate}"&gt;
                &lt;f:convertDateTime pattern="MM/dd/yyyy" /&gt;
            &lt;/p:inputText&gt; 
            &lt;p:message for="psstDate" /&gt;
            &lt;h:outputText/&gt;

            &lt;h:outputLabel for="futureDate" value="Date (@Future)"/&gt;                                
            &lt;p:inputText id="futureDate" value="\#{validationBean.futureDate}"&gt;
                &lt;f:convertDateTime pattern="MM/dd/yyyy" /&gt;
            &lt;/p:inputText&gt; 
            &lt;p:message for="futureDate" /&gt;
            &lt;h:outputText/&gt;

        &lt;/h:panelGrid&gt;

        &lt;p:commandButton value="Save" ajax="false" icon="ui-icon-check" validateClient="true" /&gt;
    &lt;/p:panel&gt;
&lt;/h:form&gt;
                    </pre>
				</p:tab>
				
				<p:tab title="ValidationBean.java">
<pre name="code" class="java">
/*
 * Copyright 2009-2012 Prime Teknoloji.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.primefaces.examples.view;

import java.util.Date;
import javax.validation.constraints.AssertTrue;
import javax.validation.constraints.DecimalMax;
import javax.validation.constraints.Digits;
import javax.validation.constraints.Future;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.Past;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import org.primefaces.examples.validate.Email;

public class ValidationBean {
    
    @Size(min=2,max=5)
    private String name;
    
    @Min(10) @Max(20)
    private Integer age;
    
    @DecimalMax(value= "99.9", message = "Shold not exceed 99.9")
    private Double amount;
    
    @Digits(integer=3,fraction=2)
    private Double amount2;

    @AssertTrue
    private boolean checked;

    @Past
    private Date pastDate;
    
    @Future
    private Date futureDate;
    
    @Pattern(regexp = "/^[-+]?\\d+$/") // integer
    private String pattern;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Double getAmount() {
        return amount;
    }

    public void setAmount(Double amount) {
        this.amount = amount;
    }

    public Double getAmount2() {
        return amount2;
    }

    public void setAmount2(Double amount2) {
        this.amount2 = amount2;
    }

    public boolean isChecked() {
        return checked;
    }

    public void setChecked(boolean checked) {
        this.checked = checked;
    }

    public Date getPastDate() {
        return pastDate;
    }

    public void setPastDate(Date pastDate) {
        this.pastDate = pastDate;
    }

    public Date getFutureDate() {
        return futureDate;
    }

    public void setFutureDate(Date futureDate) {
        this.futureDate = futureDate;
    }
    
    public String getPattern() {
        return pattern;
    }

    public void setPattern(String pattern) {
        this.pattern = pattern;
    }
}
</pre>
				</p:tab>
			</p:tabView>
			
		</div>
				
	</ui:define>
</ui:composition>